package com.tech.connect.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.tech.connect.R;
import com.tech.connect.api.AuthHttp;
import com.tech.connect.api.BaseEntityOb;
import com.tech.connect.api.UserInfo;

import java.util.Map;

public class AuthInfoActivity extends BaseActivity {

    private TextView tvCard;
    private TextView tvPhone;
    private TextView tvSkill;

    protected boolean isShowHeadBar() {
        return true;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getHeadBar().setTitle("认证中心");
        setContentView(R.layout.activity_auth_info);
        initView();
        initData();
        loadData();
    }

    private void initData() {
        tvPhone.setText(UserInfo.getUserInfo().isMobileAuth == 1 ? "已认证" : "未认证");
        tvCard.setText(UserInfo.getUserInfo().isIdentityAuth == 1 ? "已认证" : "未认证");
        tvSkill.setText(UserInfo.getUserInfo().isSkillAuth == 1 ? "已认证" : "未认证");
    }


    private void initView() {
        tvPhone = findViewById(R.id.tvPhone);
        tvCard = findViewById(R.id.tvCard);
        tvSkill = findViewById(R.id.tvSkill);
        tvPhone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                jump2Activity(AuthPhoneActivity.class, 996);
            }
        });
        tvCard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                jump2Activity(AuthCardActivity.class, 996);
            }
        });
        tvSkill.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                jump2Activity(AuthSkillActivity.class, 996);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        if (RESULT_OK == resultCode) {
            if (requestCode == 996) {
                loadData();
            }
        }
    }

    private void loadData() {
        AuthHttp.info(new BaseEntityOb<Map<String, Object>>() {
            @Override
            public void onDataDeal(boolean isSuccess, Map<String, Object> data, String msg) {
                String mobileInfo = "";
                String identityInfo = "";
                String skillInfo = "";
                if (isSuccess && data != null) {
                    Object mobileInfoO = data.get("mobileInfo");
                    if (mobileInfoO != null && mobileInfoO instanceof String) {
                        mobileInfo = (String) mobileInfoO;
                    }
                    Object identityInfoO = data.get("identityInfo");
                    if (identityInfoO != null && identityInfoO instanceof String) {
                        identityInfo = (String) identityInfoO;
                    }
                    Object skillInfoO = data.get("skillInfo");
                    if (skillInfoO != null && skillInfoO instanceof String) {
                        skillInfo = (String) skillInfoO;
                    }
                }
                tvPhone.setText(mobileInfo);
                tvCard.setText(identityInfo);
                tvSkill.setText(skillInfo);
            }
        });

    }

}